<?php
//admin管理模块
class main extends spController
{
	function __construct(){ // 公用
		parent::__construct(); // 这是必须的
		$this->tpl_title = "后台模块|主题部分";
	}
	
	function in(){
		$this->display("admin/main_in.html");
	}

	function top(){
		$this->display("admin/main_top.html");
	}
	
	function bottom(){
		$this->display("admin/main_bottom.html");
	}
	
	function index()
	{ // 这里是首页
		$user=spClass('user');
		//dump($record->select());
		$conditions= array
		(
			"userid" => $_SESSION["userinfo"]["userid"],
		);
		$list = $user->findall();
		//dump($list);
		//$path = spClass('lib_part');
		$oDOMDocument=new DOMDocument('1.0','utf-8');
		$oDOMDocument->loadXML(spClass('lib_part')->BuildPartTreeXML());
		$oRootXMLNode=$oDOMDocument->documentElement->childNodes->item(0);
		 
		$this->fpart_list=spClass("lib_part")->BuildPartTreeLabel($oRootXMLNode);
		$this->select_fpartid=array($fpartid=>'selected');
		$this->disable_partid=array($result_part['partid']=>'disabled');//用于在栏目修改时，忽略当前目录。
		//dump(spClass("lib_part")->BuildPartTreeLabel($oRootXMLNode));

		$this->list=$list;
		$this->contents = "后台模块首页内容";
		$this->display("admin/main_index.html");
	}
	function system(){
		$system = spClass("system");
		$data = array(
			'domain'=>$this->spArgs('domain'),
			'name'=>$this->spArgs('name')
		);
		if ($data['domain']==""){
			$this->system=$system->findAll();
		}else{
			$conditions=array('system_id'=>1);
			$system->update($conditions, $data);
			$this->success("修改成功",spUrl("main","system"));
		}
		$this->display("admin/main_system.html");
	}

	
	function page(){ // 监控程序测试
		$this->aas ="2";
		$this->aab ="1";
		$record = spClass('record');
		$conditions = 31;
		//array
		//(
		//	'siteid'=>'31'
		//);
		//$n=$record->etr($conditions);
		$domain = 'www.baidu.com';
		$username = 'haha';
		$mail = '516000083@qq.com';
		$user_id = '31';
		$status = 200;
		$as=array(
			'siteid'=>$conditions,
			'domain'=>$domain,
			'username'=>$username,
			'mail'=> $mail,
			'userid'=>$user_id,
			'status'=>$status
		);
		//$n=$record->alarm($conditions, $domain, $username, $mail, $user_id, $status);
		$n=$record->alarm($as);
//		dump($n);
//		dump($mail);
//		$senmail = spClass('my_fun');
//		$news = '故障提示';
//		$time = 50;
//		$senmail->sendmail($news, $time, $domain, $username, $mail);
	
		$this->contents = "后台模块其他内容";
		$this->display("admin/main_page.html");
	}
	
	function user()
	{
		$user=spClass('user');
		$list = $user->findall();
		//dump($list);
		
		$this->list=$list;
		$this->display("admin/main_user.html");
	}
	
	function e_update()
	{		
		$data = $this->spArgs();
		$Model=spClass('user');
		$where['userid'] =$data['userid'];
		if($Model->update ( $where, $data ))
		{
			echo '修改成功';
		}
		else 
		{
			echo '修改失败';
		}

	}
	
      function alarm($siteid)
      {
      	$record = spClass('record');
      	$n = $record->etc($siteid);
      	if($n[0][status_code]=200)
      	{
      		if($n[1][status_code]=200)
      		{
      			break;
      		}else
      		{
      			//计算时间差
      			$time = $n[0][addtime]-$n[1][addtime];
      			//发送	出现故障
      		}
      	}
      	else 
      	{
      		if ($n[1][status_code]=200)
      		{
      			//计算时间差
      			$time = $n[0][addtime]-$n[1][addtime];
      			//发送	故障恢复
      		}
      		else 
      		{
      			break;
      		}
      	}
      }
    
	
	
	//lj
}	